﻿using BusinessLogicLayer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PresentationLayer
{
    public partial class frmTimKiemNV : Form
    {
        public HienThiDSTKNV HienThiDS;

        public frmTimKiemNV()
        {
            InitializeComponent();
        }

        private void frmTimKiemNV_Load(object sender, EventArgs e)
        {
            cbbTrangThai.SelectedIndex = 0;
            ActionResultAsList<ChucVu> ar = new ChucVuManager().LayDS();
            if (ar.Success)
            {
                cbbChucVu.DataSource = ar.ObjectList;
                cbbChucVu.DisplayMember = "TenChucVu";
                cbbChucVu.ValueMember = "MaChucVu";
            }
            else
            {
                MessageBox.Show(ar.Exceptions[ar.Exceptions.Count - 1].Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }

        private void btnTrichLoc_Click(object sender, EventArgs e)
        {
            ActionResultAsList<NhanVien> ar = new ActionResultAsList<NhanVien>();
            if (radTenQL.Checked)
            {
                if (txtTenQL.Text.Trim() == "")
                {
                    MessageBox.Show("Vui lòng nhập tên nhân viên quản lý!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtTenQL.Focus();
                    return;
                }
                else
                    ar = new NhanVienManager().LayDSTheoNVQL(txtTenQL.Text.Trim());
            }
            else
                if (radTrangThai.Checked)
                    ar = new NhanVienManager().LayDSTheoTT(cbbTrangThai.SelectedItem.ToString());
                else
                    if (radCV.Checked)
                        ar = new NhanVienManager().LayDSTheoCV(cbbChucVu.SelectedValue.ToString());
            if (ar.Success)
                if (ar.ObjectList.Count == 0)
                    MessageBox.Show("Không tìm thấy!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    HienThiDS(ar.ObjectList);
            else
                MessageBox.Show(ar.Exceptions[ar.Exceptions.Count - 1].Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            if (txtDiaChi.Text.Trim() == "" && txtEmail.Text.Trim() == "" && txtKNCM.Text.Trim() == ""
                && txtKNNN.Text.Trim() == "" && txtTen.Text.Trim() == "" && mtxtSDT.Text.Trim() == "")
            {
                MessageBox.Show("Vui lòng nhập thông tin tìm kiếm!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                ActionResultAsList<NhanVien> ar = new NhanVienManager().TimKiem(txtTen.Text.Trim(), mtxtSDT.Text.Trim(), txtDiaChi.Text.Trim(), txtEmail.Text.Trim(), txtKNNN.Text.Trim(), txtKNCM.Text.Trim());
                if (ar.Success)
                    if (ar.ObjectList.Count == 0)
                        MessageBox.Show("Không tìm thấy!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    else
                        HienThiDS(ar.ObjectList);
                else
                    MessageBox.Show(ar.Exceptions[ar.Exceptions.Count - 1].Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
